/*
 * Copyright (c) zhg2yqq.com Corp.
 * All Rights Reserved.
 */
package com.zhg2yqq.wheels.security.multi;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhg2yqq, 2023年3月16日
 * @version zhg2yqq v1.0
 */
public class AuthenticationTokenProducer {
    private final Map<String, IAuthenticationTokenFactory> factories = new HashMap<>();
    private final IAuthenticationTokenFactory defaultFactory = new NormalAuthenticationTokenHandler.NormalAuthenticationTokenFactory();

    public AuthenticationTokenProducer() {
        factories.put(defaultFactory.type(), defaultFactory);
    }

    public AuthenticationTokenProducer(Map<String, IAuthenticationTokenFactory> factories) {
        factories.put(defaultFactory.type(), defaultFactory);
        factories.putAll(factories);
    }

    public void addAuthenticationTokenFactory(IAuthenticationTokenFactory factory) {
        factories.put(factory.type(), factory);
    }

    public CustomAuthenticationToken create(String type, AuthenticationTokenParameter parameter) {
        return factories.getOrDefault(type, defaultFactory).create(parameter);
    }

    public Map<String, IAuthenticationTokenFactory> getFactories() {
        return factories;
    }
}
